package tripController;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.redis.Redis;

import jfinalUtil.OtherUtil;
import tripModel.Location;
import tripModel.Total;
import tripService.LocationService;
import tripService.TotalService;

public class TripController extends Controller {
	public void index() {
		// setAttr("topLocation", "");
		// setAttr("hotLocation", "");
		List<Total> list = TotalService.showTotal();
		Redis.use().set("totalList", list);
		setAttr("totalList", list);
		super.render("/WEB-INF/jsp/main.jsp");
	}

	@SuppressWarnings("unchecked")
	public void showLocationByTotal() {
		List<Total> list = null;
		Object o = Redis.use().get("totalList");
		if (o.equals("nil")) {
			list = TotalService.showTotal();
			Redis.use().set("totalList", list);
			System.out.println("没有缓存");
		} else {
			list = (List<Total>) o;
			System.out.println("有缓存");
		}
		Long tID = getParaToLong(0);
		String str = getPara(1);
		String tName = OtherUtil.codingToUTF8(str);
		int pageNumber = getParaToInt(2, 1);
		Page<Location> page = LocationService.findLocationByTotal(tID, pageNumber);
		setAttr("tID", tID);
		setAttr("tName", tName);
		setAttr("page", page);
		setAttr("totalList", list);
		// String path = getRequest().getContextPath();
		render("/WEB-INF/jsp/showByTotal.jsp");
	}
}
